<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <p>我是第一行内容</p>
        <p id='two'>我是第二行内容</p>
        <p>我是第三行内容</p>
        <p>我是第四行内容</p>
        <button>将第2行内容替换为JavaScript课程<tton>
    </div>
    <script>
        var btn = document.querySelector('button');
        btn.onclick = function() {
            var div1 = document.querySelector('div')
            var p2 = div1.querySelector('#two');
            var newdiv = document.createElement('div');
            var text = document.createTextNode('JavaScript课程');
            newdiv.appendChild(text);
            div1.replaceChild(newdiv, p2);
        }
    </script>
</body>